/* eslint-disable keyword-spacing,indent */
// +----------------------------------------------------------------------
// | CmsWing [ 网站内容管理框架 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2115 http://www.cmswing.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: arterli <arterli@qq.com>
// +----------------------------------------------------------------------

module.exports = class extends think.cmswing.admin {
    constructor(ctx) {
        super(ctx); // 调用父级的 constructor 方法，并把 ctx 传递进去
        // 其他额外的操作
        this.tactive = 'organization';
    }
    /**
     * index action
     * @return {Promise} []
     */
    async salesmanAction() {
        const query = unflatten(this.get());
        delete query.page;
        query.is_admin = 0;
        query.groupid = 12;
        const dataSelect = await this.model('zzjg').order('id asc').select();
        const data = await this.model('member').where(query).page(this.get('page') || 1, 20).order('shenheshijian desc').countSelect();
        const html = this.pagination(data);
        // this.assign('dataMap', dataMap);
        this.assign('dataSelect', dataSelect);
        this.assign('pagerData', html); // 分页展示使用
        this.assign('list', data.data);
        this.meta_title = '业务员';
        return this.display();
    }

    async adminAction() {
        const query = unflatten(this.get());
        delete query.page;
        query.is_admin = 1;
        const dataSelect = await this.model('zzjg').order('id asc').select();
        const dataMap = {};
        if(!query.zzjg) {
            query.zzjg = ['in', []];
            dataSelect.forEach(e => {
                query.zzjg[1].push(e.id);
            });
        }
        dataSelect.forEach(e => {
            dataMap[e.id] = e.zzjg;
        });

        const data = await this.model('cmswing/member').where(query).page(this.get('page') || 1, 20).order('shenheshijian desc').countSelect();
        const html = this.pagination(data);
        this.assign('dataMap', dataMap);
        this.assign('dataSelect', dataSelect);
        this.assign('pagerData', html); // 分页展示使用
        this.assign('list', data.data);
        this.meta_title = '管理人员';
        return this.display();
    }
};
